<template>
  <div class="count">
    <h1>欢迎来到{{school}}学习，{{$store.getters.upperSchool}}</h1>
    <h2>当前求和为：{{sum}}，当前和放大10倍后：{{$store.getters.bigSum}}</h2>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="add">+</button>
    <button @click="sub">-</button>
    <button @click="oddAdd">当前和为奇数再加</button>
    <button @click="waitAdd">等一等再加</button>
    <button @click="serverAdd">问问服务器到底加几</button>
    <button @click="test">测试（一会删）</button>
  </div>
</template>

<script>
  import {mapState} from 'vuex'
  export default {
    name:'Count',
    data() {
      return {
        n:1 //用户选择的数字
      }
    },
    computed: {
      ...mapState(['sum','school']),
      /* school(){
        return this.$store.state.school
      },
      sum(){
        return this.$store.state.sum
      } */
    },
    methods: {
      // 加
      add(){
        this.$store.commit('JIA',this.n)
        console.log(this.$store)
      },
      // 减
      sub(){
        this.$store.commit('JIAN',this.n)
      },
      // 奇数再加
      oddAdd(){
        this.$store.dispatch('jiaOdd',this.n)
      },
      // 等一等再加
      waitAdd(){
        this.$store.dispatch('jiaWait',this.n)
      },
      // 问问服务器再加
      serverAdd(){
        this.$store.dispatch('jiaServer')
      },
      test(){
        let x = mapState(['sum','school'])
        console.log(x)
      }
    },
  }
</script>

<style scoped>
  .count {
    background-color: skyblue;
    border-radius: 10px;
    box-shadow: 0 0 10px;
    padding: 10px;
  }
  button,select {
    margin-right: 5px;
  }
</style>